import express from 'express';
import { findUsers, client } from '../mongodb/user/index.js';
const router = express.Router();

router.get('/user', async function (req, res, next) {
  try {
    const usersCursor = findUsers(
      { name: '李小龙' },
      {
        projection: {
          name: 1,
        },
      },
    );
    const users: any[] = [];
    for await (const user of usersCursor) {
      users.push(user);
    }
    res.send(users);
  } catch (err) {
    res.status(500).send(err);
  } finally {
    client.close();
  }
});

export default router;
